<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增商户提现')"/>
    <style>
        .cash {
            margin-bottom: 10px;
            padding: 15px;
            line-height: 22px;
            border-left: 5px solid #5874c8;
            border-radius: 0 2px 2px 0;
            background-color: #f2f2f2;
        }

        .cash span {
            padding-right: 20px;
        }
    </style>
</head>
<body class="white-bg">
<div class="cash">
    <span style="color: red;font-size: 20px" th:text="'可提现金额:' + ${vwBusinessCashStat.cashSum}"></span>
    <span style="color: grey;font-size: 20px" th:text="'冻结金额:' + ${vwBusinessCashStat.frzzingCash}"></span>
    <span style="color: red;font-size: 20px"  th:text="'单笔最低金额¥:' + ${businessCaptialSetting.minAmount}"></span>
    <span style="color: red;font-size: 20px" th:text="'单笔最高金额¥:' + ${businessCaptialSetting.maxAmount}"></span>
</div>
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-businessCapital-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">提现金额：</label>
            <div class="col-sm-8">
                <input id="amount" name="amount" class="form-control" type="number" required onchange="onChangeValue()">
                <div th:text="'注:每笔提现手续费单笔 ' + ${businessCaptialSetting.rate} +' 元，直接在提现金额中扣除。' "></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">到账金额：</label>

            <div class="col-sm-8">
                <input id="realAmount" name="realAmount" class="form-control" type="number" disabled>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">手续费：</label>
            <div class="col-sm-8">
                <input id="fee" name="fee" class="form-control" type="number" th:value="${businessCaptialSetting.rate}" disabled>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">请选择银行卡：</label>
            <div class="col-sm-8">
                <select style="width: 100%;height: 36px; border: 1px solid #ddd;" name="bank" required>
                    <option th:each="bankInfo,userStat:${bankInfos}" th:value="${bankInfo.bankId}"
                            th:text="${bankInfo.bankName}+'/'+${bankInfo.bankNo}+'/'+${bankInfo.userName}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <input id="remark" name="remark" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label"><span style="color: red; ">*</span>支付密码：</label>
            <div class="col-sm-8">
                <input id="password" name="password" class="form-control" type="password" required>
            </div>
        </div>
    </form>
</div>
<!-- 全局js -->
<script src="https://cdn.staticfile.org/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdn.staticfile.org/jquery.blockUI/2.70.0-2014.11.23/jquery.blockUI.min.js"></script>
<script src="https://cdn.staticfile.org/jquery-validate/1.13.0/jquery.validate.min.js"></script>
<script src="https://cdn.staticfile.org/jquery-validate/1.13.0/localization/messages_zh.min.js"></script>
<script th:src="@{/ajax/libs/layer/layer.min.js}"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/layui/2.4.3/layui.min.js"></script>
<script th:src="@{/ruoyi/js/common.js?v=3.3.0}"></script>
<script th:src="@{/ruoyi/js/ry-ui.js?v=3.3.0}"></script>
<script th:src="@{/ajax/libs/validate/jquery.validate.extend.js}"></script>
<script th:inline="javascript">
    var ctx = [[@{/}]];
</script>
<script th:src="@{/js/md5.min.js}"></script>
<script th:src="@{/js/pwdMd5.js}"></script>
<script type="text/javascript">
    var rate = [[${businessCaptialSetting.rate}]]
    function onChangeValue() {
        var amount = $('#amount').val();
        var result = amount -rate;
        if (result < 0) {
            result = 0;
        }
        $('#realAmount').val(result);
    }
    var min = [[${businessCaptialSetting.minAmount}]]
    var max = [[${businessCaptialSetting.maxAmount}]]
    var prefix = ctx + "channel/businessCapital"
    $("#form-businessCapital-add").validate({
        onkeyup: false,
        rules: {
            amount: {
                max: max,
                min: min,
                required: true
            },
            password: {
                required: true,
                remote: {
                    url: ctx + "channel/businessInfo/checkPassword",
                    type: "get",
                    dataType: "json",
                    data: {
                        password: function () {
                            return md5($("input[name='password']").val());
                        }
                    }
                }
            },
            bank: {
                required: true
            }
        },
        messages: {
            password: "请输入正确的支付密码"
        },
        focusCleanup: true
    });

    function submitHandler() {
        var amount = $('#amount').val();
        var cashSum = [[${vwBusinessCashStat.cashSum}]];
        if (amount > cashSum) {
            $.modal.alertWarning("您所填写的金额超出可提现的金额,请重新填写！");
            return;
        }

        if ((amount - rate) <=0 ) {
            $.modal.alertWarning("您的提现金额不足以扣除手续费！");
            return;
        }

        var data = $("#form-businessCapital-add").serializeArray();
        getMd5PwdByArray(data);
        data.push({name: 'fee', value: rate})
        data.push({name: 'realAmount', value: amount - rate})

        if ($.validate.form()) {
            $.operate.save(prefix + "/add",data);
        }
    }
</script>
</body>
</html>
